package com.yotta.operationdatascreencode.web.serialier;

import com.yotta.operationdatascreencode.base.entity.TestUserEntity;
import com.yotta.operationdatascreencode.common.core.BasePageResult;
import com.yotta.operationdatascreencode.web.response.TestRsp;
import java.util.ArrayList;
import java.util.List;

/**
 * 响应序列化
 */
public class TestUserSerialier {

    /**
     * 序列化列表
     * @param models  数据源
     * @return 响应结果
     */
    public static BasePageResult<TestRsp> listSerializer(
        BasePageResult<TestUserEntity> models) {

        List<TestRsp> datas = new ArrayList<>();
        models.getData().forEach(e -> {
            TestRsp tmp = new TestRsp();
            tmp.setCityName(e.getName());
            tmp.setCityCode(e.getName());
            datas.add(tmp);
        });
        BasePageResult<TestRsp> rsp = new BasePageResult<TestRsp>(datas,
            models.getTotalNum(), models.getPageNum(), models.getPageSize());
        return rsp;
    }
}
